package com.yueya.basic.dict.model;

import java.util.List;

import com.jfinal.aop.Duang;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.yueya.basic.dict.service.DictService;

@SuppressWarnings("serial")
public class Dict extends Model<Dict> {

	public static Dict dao = new Dict();

	public static DictService service = Duang.duang(DictService.class);

	public String getValue(String category) {
		String value = null;
		if(StrKit.notBlank(category)){
			Dict dict = findFirst("SELECT * FROM t_dict WHERE category=?", category);
			if(null != dict){
				value = dict.getStr("dict_value");
			}
		}
		return value;
	}
	
	
	public String getName(String category, String value) {
		String v = "";
		String sql = "select name from t_dict d where category = ? and dict_value = ?";
		Record r = Db.findFirst(sql, category, value);
		if (r != null) {
			v = r.getStr("name");
		}
		return v;
	}


	public List<Dict> findByCategory(String category) {
		String sql = "select * from t_dict where category = ?";
		return Dict.dao.find(sql , category);
		
	}
}
